﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace homework1
{
    internal class Array
    {
        private int[] arr;
        private int size;

        public Array(int[] arr, int size)
        {
            this.arr = arr;
            this.size = size;
        }

        public Array()
        {
            arr = null;
            size = 0;
        }

        public Array(int size)
        {
            this.size = size;
            arr = new int[size];
            for (int i = 0; i < size; i++)
                arr[i] = 0;
        }

        public void setSize(int size)
        {
            if (size < this.size)
            {
                throw new Exception("Size is too small");
            }
            int[] temp= new int[size];
            for (int i = 0; i < this.size; i++)
                temp[i] = arr[i];
            arr = temp;
            this.size = size;
        }

        public int getSize() { return arr.Length; }

        public double getAverage()
        {
            double sum = 0;
            foreach(int i in this.arr) {
                sum += i;
            }
            return sum / size;
        }

        public int getSum()
        {
            int sum = 0;
            foreach (int i in this.arr)
            {
                sum += i;
            }
            return sum;
        }

        public int getMax()
        {
            int max = arr[0];

            foreach (int i in arr)
            {
                if (max < i)
                {
                    max = i;
                }
            }

            return max;
        }

        public int getMin()
        {
            int min = arr[0];

            foreach (int i in arr)
            {
                if(min > i) {
                min = i;
                }
            }
            return min;
        }

        public void addItem(int item)
        {
            setSize(size + 1);
            arr[size - 1] = item;
        }

        public string toString()
        {
            string str = "";
            foreach (int i in arr)
            {
                str += i + " ";
            }
            return str;
        }
    }
}
